<template>
	<view class="mainpadding" v-if="pageShow">
		<template v-if="type==0">
			<template v-if="dataAll.state==1">
				<view class="bigtext fonweight xiaohei">待支付</view>
				<view class="xiaohui margin_top2 ershil">请您及时支付~</view>
			</template>
			<template v-if="dataAll.state==2">
				<view class="bigtext fonweight xiaohei">已支付</view>
				<view class="xiaohui margin_top2 ershil">您已成功支付~</view>
			</template>
			<template v-if="dataAll.state==3">
				<view class="bigtext fonweight xiaohei">已取消</view>
				<view class="xiaohui margin_top2 ershil">您已取消支付</view>
			</template>
		</template>
		<template v-if="type==1">
			<template v-if="dataAll.state==1">
				<view class="bigtext fonweight xiaohei">待支付</view>
				<view class="xiaohui margin_top2 ershil">等待用户支付~</view>
			</template>
			<template v-if="dataAll.state==2">
				<view class="bigtext fonweight xiaohei">已支付</view>
				<view class="xiaohui margin_top2 ershil">用户支付成功~</view>
			</template>
			<template v-if="dataAll.state==3">
				<view class="bigtext fonweight xiaohei">已取消</view>
				<view class="xiaohui margin_top2 ershil">用户取消支付</view>
			</template>
		</template>
		<view class="mainpadding_top ffffff radius">
			<view class="xiaohei fonweight titletext">订单产品</view>
			<view class="flexleft margin_top">
				<image :src="dataAll.dmkj_image_text" class="listleftimg radius margin_right2" mode=""></image>
				<view class="" style="width: 100%;">
					<view class="titletext xiaohei">{{dataAll.dmkj_name}}</view>
					<view class="xiaohuang smalltext margin_top">
						<text>￥</text>
						<text class="titletext fonweight">{{dataAll.pay_price}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius flexbetween">
			<view class="ershiba xiaohei">开奖号</view>
			<view class="titletext xiaohuang fonweight">{{dataAll.dmkj_hm}}</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween">
				<view class="ershiba xiaohei">金额</view>
				<view class="titletext xiaohuang fonweight">￥{{dataAll.pay_price}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershiba xiaohei">订单编号</view>
				<view class="ershiba xiaohui">{{dataAll.order_no}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershiba xiaohei">下单时间</view>
				<view class="ershiba xiaohui">{{dataAll.createtime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.state==2">
				<view class="ershiba xiaohei">支付方式</view>
				<view class="ershiba xiaohui">金币支付</view>
			</view>
		</view>
		<view class="gudingdb mainpadding" v-if="type==0">
			<view class="flexright margin_top" v-if="dataAll.state==1 || dataAll.state==3">
				<view class="listbtnhui margin_right" v-if="dataAll.state==1" @click.stop="cancelItem(listid,'/api/ordercl/cancelOrder')">取消订单</view>
				<view class="listbtnlan" v-if="dataAll.state==1" @click.stop="buy(dataAll)">立即支付</view>
				<view class="listbtnhui" v-if="dataAll.state==3" @click.stop="delItem(listid,'/api/ordercl/delOrder')">删除订单</view>
			</view>
		</view>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				modal:{
					modalShow:false,
					title:"",
				},
				currentapi:"",
				currentid:"",
				listid:"",
				pageShow:false,
				dataAll:{},
				type:0//1商家订单详情
			}
		},
		onLoad(options) {
			this.listid = options.id
			if(options.type){
				this.type = options.type
			}
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			buy(dataAll){
				uni.navigateTo({
					url:"/pages_index/querendd?id="+dataAll.dmkj_id+"&price="+dataAll.pay_price+"&order_id="+dataAll.id
				})
			},
			cancelItem(id,url){
				this.currentapi = url
				this.currentid = id
				this.modal.title="是否确认取消订单？"
				this.modal.modalShow = true
			},
			delItem(id,url){
				this.currentapi = url
				this.currentid = id
				this.modal.title="是否确认删除当前订单？"
				this.modal.modalShow = true
			},
			modalSure(){
				if(this.modal.title=="是否确认取消订单？"){
					this.cancelorder()
				}else if(this.modal.title=="是否确认删除当前订单？"){
					this.delOrder()
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			cancelorder(){
				httpRequest.request(this.currentapi, 'GET', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.getDetail()
					}
				})
			},
			delOrder(){
				httpRequest.request(this.currentapi, 'POST', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			getDetail() {
				httpRequest.request('/api/ordercl/orderDetail', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					this.dataAll = res.data
					this.pageShow = true
				})
			},
		}
	}
</script>

<style>

</style>
